package mmusimulator;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 *
 * @author Michal
 */
public class Processor {
    
    byte[][] program;
    int lastAdressPosition = 0;
    
    public Processor(){
        init();
    }
    
   
    public byte[] getNextVirtualAddress(){
       System.out.print("INFO: Zpracovánám virtuální adresu: ");
       Simulator.printArray(program[lastAdressPosition]);
       return program[lastAdressPosition];  
    }

   

    private void init() {
 
	readSSV();  
    
    }

 

    private void readSSV() {
        
        String ssvFile = "src/mmusimulator/traces/traceC.ssv";
        BufferedReader br = null;
        String line = "";
        String ssvSplitBy = " ";
        int index = 0;
        int lineCount =0;
 
        try {
                br = new BufferedReader(new FileReader(ssvFile));           
                while ((line = br.readLine()) != null) {
                        lineCount++;
                }
                
                program = new byte[lineCount][24];
            
                br = new BufferedReader(new FileReader(ssvFile));           
                while ((line = br.readLine()) != null) {
 
                        String[] splitedString = line.split(ssvSplitBy);
                        
                        program[index] = Simulator.decimalToBinaryArray(Integer.parseInt(splitedString[1],16));
                        index++; 
                       // System.out.println(Integer.parseInt(splitedString[1]));
                                

                }
 
        } catch (FileNotFoundException e) {
                e.printStackTrace();
        } catch (IOException e) {
                e.printStackTrace();
        } finally {
                if (br != null) {
                        try {
                                br.close();
                        } catch (IOException e) {
                                e.printStackTrace();
                        }
                }
        }
 
        System.out.println("INFO: Soubor s virtuálními adresami byl načten úspěšně ");
        System.out.println("--------------------------------------------");
    
    
        
    }
    
     
    
   
        
    
}


    
    
    

